Skip to content

fix: expose the selected label as the value of a select-only combobox - #1259

Open
Tibefox wants to merge 1 commit into
react-component:masterfrom
Tibefox:codex/select-readonly-combobox-value
Open

Tibefox wants to merge 1 commit into
react-component:masterfrom
Tibefox:codex/select-readonly-combobox-value

Conversation

@Tibefox

@Tibefox Tibefox commented Nov 22, 2026 •

Copy link
Copy Markdown

Related to ant-design/ant-design#52987.

In Ant Design's Basic Usage example, the selected option is visible next to the read-only input. Tabbing into the control exposes a focused combobox with an empty value. Its selected label is available separately in a polite live region.

For a single select with search disabled, this change gives the built-in input the selected string or numeric label as its native value. The existing label still handles visual rendering. The live region is skipped when the input already exposes the selection. Searchable inputs keep their query, and rich labels and custom inputs keep their existing announcement behavior.

I tested antd 6.7.1 with the released select package and with this patch in Chromium 156 on macOS. With a field labelled Owner, the accessibility tree showed:

Action 1.12.0 combobox value Patched combobox value
Tab to the field with Lucy selected Empty Lucy
Select Jack with the keyboard Empty Jack
Activate Clear Empty Empty
Type j in a separate searchable field j j

The field name stayed Owner after selection. Validation covered the browser accessibility tree. The exact VoiceOver announcement still needs confirmation on a screen-reader setup.

The regression test fails on master with an empty value for Lucy. All 453 tests and 21 snapshots pass with the patch. TypeScript, lint and compilation also pass.

Summary by CodeRabbit

  • 无障碍
    • 优化仅选择模式下的标签呈现与辅助技术播报;支持文本和数字标签,包括 0。
    • 搜索输入与已选标签保持独立,非文本标签仍可通过辅助播报获取。

@vercel

vercel Bot commented Nov 22, 2026

Copy link
Copy Markdown

@Tibefox is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

BaseSelect 在单个选中项的标签为字符串或数字且满足指定条件时,生成只读值并传递给输入框。该值存在时,输入框显示该值并隐藏 Polite。新增无障碍测试覆盖文本标签、搜索输入及非文本标签。

Changes

只读选中值

Layer / File(s) Summary
生成并传递只读值
src/hooks/useBaseProps.ts, src/BaseSelect/index.tsx
上下文新增可选的 readOnlyValue。BaseSelect 在恰有一个显示值、标签为字符串或数字,且未启用指定模式、搜索或自定义组件时生成该值,并传入上下文。
输入呈现与无障碍测试
src/SelectInput/Content/SingleContent.tsx, src/BaseSelect/index.tsx, tests/Accessibility.test.tsx
有 readOnlyValue 时,SingleContent 将其用作输入值并设置透明度为 0;BaseSelect 不显示 Polite。测试覆盖文本和数字标签、空选择、搜索输入及非文本标签。

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: zombiej

Merge Risk: Minimal · up to 06a8c

Select-only comboboxes now expose the selected text or numeric label as the input value, and the live region is skipped when the input already exposes it. No concrete merge-blocking risk remains. The actual screen-reader announcement is still to be confirmed on a real setup.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题“fix: expose the selected label as the value of a select-only combobox”与变更内容一致。变更在无搜索的单选模式下,把已选文本标签(字符串或数字)作为内置输入框的 value 暴露出来。SingleContent 使用 readOnlyValue 设置输入值,BaseSelect 计算该值并通过上下文传递,同时在该值已定义时抑…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

标题“fix: expose the selected label as the value of a select-only combobox”与变更内容一致。变更在无搜索的单选模式下,把已选文本标签(字符串或数字)作为内置输入框的 value 暴露出来。SingleContent 使用 readOnlyValue 设置输入值,BaseSelect 计算该值并通过上下文传递,同时在该值已定义时抑制 Polite 输出。新增的无障碍测试也覆盖了该行为。标题简洁,说明了主要变更。

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

我是兔子,蹦到选择框旁,
看见 Lucy,标签写进输入行。
数字零也变成清楚的字,
搜索时,输入仍听从键盘。
非文本标签,让 live region 轻声报上。

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 82ac5aea-1987-40ae-96b3-1b4669c199bb
Commits

Reviewing files that changed from the base of the PR and between fcbd87e and 06a8cba.

Files selected for processing: 4

  • src/BaseSelect/index.tsx
  • src/SelectInput/Content/SingleContent.tsx
  • src/hooks/useBaseProps.ts
  • tests/Accessibility.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant